Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(error): add known error codes constants #1602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aerialls
Copy link

This PR adds constants for known Postgres error codes. This allows more easily to perform the following checks without the need to look at the documentation for the associated codes.

	if err != nil {
		var pgErr *pgconn.PgError
		if errors.As(err, &pgErr) {
			if pgErr.Code == pgconn.PgErrorUniqueViolationCode {
				// ...
			}
			
		}

		return nil, err
	}

The list was extracted from the official postgres repository.

@jackc
Copy link
Owner

jackc commented May 15, 2023

I think this repo will do what you want: https://github.com/jackc/pgerrcode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants